﻿$.fn.dataTableExt.afnSortData['dom-checkbox'] = function (oSettings, iColumn) {
    var aData = [];
    $('td:eq(' + iColumn + ') input', oSettings.oApi._fnGetTrNodes(oSettings)).each(function () {
        aData.push(this.checked == true ? "0" : "1");
    });
    return aData;
}
function blankInBottom(x, y) {
    if (x == y) {
        return 0
    }
    else if (x == "") {
        return 1;
    }
    else if (y == "") {
        return -1;
    }
}
jQuery.fn.dataTableExt.oSort['string-case-asc'] = function (x, y) {
    var xBackup = x;
    var yBackup = y;
    x = x.toUpperCase();
    y = y.toUpperCase();
    return blankInBottom(xBackup, yBackup) != null ? blankInBottom(xBackup, yBackup) : ((x < y) ? -1 : ((x > y) ? 1 : (xBackup < yBackup) ? -1 : ((xBackup > yBackup) ? 1 : 0)));
};

jQuery.fn.dataTableExt.oSort['string-case-desc'] = function (x, y) {
    var xBackup = x;
    var yBackup = y;
    x = x.toUpperCase();
    y = y.toUpperCase();
    return ((x < y) ? 1 : ((x > y) ? -1 : (xBackup < yBackup) ? 1 : ((xBackup > yBackup) ? -1 : 0)));
};

jQuery.fn.dataTableExt.oSort['number-case-asc'] = function (xsource, ysource) {
    var x = parseFloat(xsource);
    var y = parseFloat(ysource);
    return blankInBottom(xsource, ysource) != null ? blankInBottom(xsource, ysource) : ((x < y) ? -1 : ((x > y) ? 1 : 0));
};

jQuery.fn.dataTableExt.oSort['number-case-desc'] = function (xsource, ysource) {
    var x = parseFloat(xsource);
    var y = parseFloat(ysource);
    return ((x < y) ? 1 : ((x > y) ? -1 : 0));
};

jQuery.fn.dataTableExt.oSort['date-case-asc'] = function (xsource, ysource) {
    var x = $.datepicker.parseDate("dd M y", xsource);
    var y = $.datepicker.parseDate("dd M y", ysource);
    return blankInBottom(xsource, ysource) != null ? blankInBottom(xsource, ysource) : ((x < y) ? -1 : ((x > y) ? 1 : 0));
};

jQuery.fn.dataTableExt.oSort['date-case-desc'] = function (xsource, ysource) {
    var x = $.datepicker.parseDate("dd M y", xsource);
    var y = $.datepicker.parseDate("dd M y", ysource);
    return ((x < y) ? 1 : ((x > y) ? -1 : 0));
};